package com.example.demo.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @ClassName: KaptchaConfig
 * TODO:写注释
 * @Author: zjf
 * @CreateDate: 2020-11-04 08:53
 * @Version: 0.0.1
 */
@Configuration
public class KaptchaConfig {

    @Bean
    public Producer kaptchaProducer(){
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width", "100");  //验证码图片宽度  默认为200
        properties.setProperty("kaptcha.image.height", "40");  //验证码图片高度  默认为50
        properties.setProperty("kaptcha.textproducer.font.size", "32");     //验证码文本字符大小  默认为40
        properties.setProperty("kaptcha.textproducer.font.color", "0,0,0");     //验证码文本字符颜色  默认为Color.BLACK
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYAZabcdefghijklmnopqrstuvwxyz");    // 验证码文本字符内容范围  默认为abcde2345678gfynmnpwx
        properties.setProperty("kaptcha.textproducer.char.length", "4");    //验证码文本字符长度  默认为5
        //properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");       //验证码噪点生成对象  默认为DefaultNoise

        properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");// 字体
        DefaultKaptcha kaptcha = new DefaultKaptcha();
        Config config = new Config(properties);
        kaptcha.setConfig(config);
        return kaptcha;
    }
}
